export const StorageKey = {
  token: "token",
  tokenExpire: "tokenExpire",
  userId: "userId",
  username: "username",
  name: "name",
  nickname: 'nickname',
  tel: "tel",
  email: "email",
  role: 'role',
  isAdmin:'isAdmin',
  copiedWidgets: 'copiedWidgets',
  originCopyBoxRect: 'originCopyBoxRect',
  refreshToken:'refreshToken',
  tokenLimit:'tokenLimit',
  tokenTime:'tokenTime',
  copiedActions:'copiedActions'
};

export function setStorage(key, content) {
  const _content = typeof content !== "string" ? JSON.stringify(content) : content;
  localStorage.setItem(key, _content || "");
}

export function getStorage(key, needParse = false) {
  if (!localStorage.getItem(key)) return "";

  if (needParse) return JSON.parse(localStorage.getItem(key) || "");

  return localStorage.getItem(key) || "";
}

export function clearStorage(key) {
  if (key) {
    localStorage.removeItem(key);
    return;
  }
  Object.keys(StorageKey).forEach((k) => {
    localStorage.removeItem(k);
  });
}
